<?php
session_start();
if ($_SESSION["access"] != "granted")
{
   session_destroy();
   header("Location: ./index.php");
}
require_once('f.php');

$msg = '';
if (isset($_POST['url']) && $_POST['url'] != '')
{
   $url = $_POST['url'];

   $settings = loadSettings();

   $folder = $settings['destination'];
   if ($_POST['db'] == 'on') $folder = $settings['dropbox_folder'];
   if ($_POST['tor'] == 'on') $folder = $settings['torrent_folder'];
   $recursion = '';
   if ($_POST['rec'] == 'on') $recursion = $settings['recursion'];

   $cmd = $settings['command'].' '.$recursion.' '.$settings['parameters'].$folder.' '.$url;
   $pid = shell_exec("nohup $cmd > /dev/null 2> /dev/null & echo $!");   
   $msg = "[PID:$pid] Download in progress for: ".$url;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="yes" name="apple-mobile-web-app-capable" />
<meta content="index,follow" name="robots" />
<meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type" />
<link href="pics/homescreen.gif" rel="apple-touch-icon" />
<meta content="minimum-scale=1.0, width=device-width, maximum-scale=0.6667, user-scalable=no" name="viewport" />
<link href="css/style.css" rel="stylesheet" media="screen" type="text/css" />
<script src="javascript/functions.js" type="text/javascript"></script>
<title><?php echo getTitle()?></title>
</head>

<body>

<div id="topbar">
	<div id="title">
		<?php echo getTitle()?></div>
	<div id="leftbutton"> 
		<a href="index.php" class="noeffect">Logout</a> </div>
</div>
<div id="tributton">
	<div class="links">
		<a id="pressed" href="main.php">Main</a><a href="status.php">Status</a><a href="settings.php">Settings</a></div>
</div>
<div id="content">	
   <?php if ($msg != ''):?>
	<ul class="pageitem">
		<li class="textbox"><span class="header">Success!</span><?php echo $msg?></li>
	</ul>
   <?php endif;?>
	<form method="post" action="main.php">
		<fieldset><span class="graytitle">URL</span>
		<ul class="pageitem">
			<li class="bigfield"><input placeholder="Paste url to download" type="text" name="url" id="url" /></li>			
		</ul>				
		<span class="graytitle">Options</span>
		<ul class="pageitem">
			<li class="checkbox"><span class="name">Recursively (!)</span>
			<input type="checkbox" name="rec" id="rec" /> </li>
			<li class="checkbox"><span class="name">Dropbox</span>
			<input type="checkbox" name="db" id="db" /> </li>		
			<li class="checkbox"><span class="name">Torrent</span>
			<input type="checkbox" name="tor" id="tor" /> </li>					
		</ul>				
		<ul class="pageitem">
      <li class="button">
			<input name="Submit input" type="submit" value="Start!" /></li>
      </ul>
		</fieldset></form>
</div>
<div id="footer">
	<a href="http://iwebkit.net">Powered by iWebKit</a></div>

</body>

</html>
